package com.gavel.database;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.util.ResourceBundle;

public class DataSourceHolder {

    private static DataSourceHolder INSTANCE = new DataSourceHolder();


    private DataSource dataSource = null;

    public DataSourceHolder() {

        ResourceBundle resource = ResourceBundle.getBundle("application");


        /**
         * spring.datasource.url = jdbc:mysql://127.0.0.1:3306/jingsu?useUnicode=true&characterEncoding=utf-8&useSSL=false
         * spring.datasource.driver = com.mysql.jdbc.Driver
         * spring.datasource.username = root
         * spring.datasource.password = dell@2020
         */
//
        DruidDataSource druidDataSource = new DruidDataSource();

        druidDataSource = new DruidDataSource();
        //druidDataSource.setDriverClassName(resource.getString("spring.datasource.driver"));
        druidDataSource.setUsername(resource.getString("spring.datasource.username"));
        druidDataSource.setPassword(resource.getString("spring.datasource.password"));
        druidDataSource.setUrl(resource.getString("spring.datasource.url"));
        druidDataSource.setInitialSize(5);
        druidDataSource.setMinIdle(1);
        druidDataSource.setMaxActive(10);
        // 启用监控统计功能  dataSource.setFilters("stat");
        // for mysql  dataSource.setPoolPreparedStatements(false);
        druidDataSource.setPoolPreparedStatements(false);

        dataSource = druidDataSource;
    }

    public static DataSourceHolder getInstance() {
        return INSTANCE;
    }

    public static DataSource dataSource(){
        return INSTANCE.dataSource;
    }
}
